#ifndef T_BOX_MEDIA_H
#define T_BOX_MEDIA_H

#include "stable.h"
#include "t_av_packet.h"
#include "t_box_seek_manager.h"
#include "input/t_box_input_sequence.h"

class T_Box_Core
{
protected:
    T_Box_Sequence *m_sequence;
    T_Stopwatch m_stopwatch;
    T_Box_Seek_Manager m_seek_mgr;
public:
    explicit T_Box_Core(T_Box_Sequence *a_sequence)
        : m_sequence(a_sequence)
    {
    }
    T_Box_Sequence *sequence()
    {
        return m_sequence;
    }
    T_Stopwatch *timeline()
    {
        return &m_stopwatch;
    }
    T_Box_Seek_Manager *seekManager()
    {
        return &m_seek_mgr;
    }
    void setMediaDuration(qint64 a_duration)
    {
        this->seekManager()->setMediaDuration(a_duration);
    }
};

class T_Box_Control
{
protected:
    bool m_valid;
    T_Box_Core *m_core;
    T_Box_Thread *m_thread;
    T_Box_Input_Sequence *m_input;
    AVFormatContext	*m_format_ctx;
public:
    explicit T_Box_Control(T_Box_Core *a_core, T_Box_Thread *a_thread);
    ~T_Box_Control();
    bool isValid();
    AVFormatContext	*formatContext();
    T_Box_Thread *controlThread();
    T_AV_Packet *readPacket();
    class T_Box_Media *openMedia(AVMediaType a_media_type);
};

class T_Box_Media
{
protected:
    bool m_valid;
    T_Box_Control *m_control;
    AVMediaType m_media_type;
    int m_stream_index;
    AVStream *m_stream;
    AVCodecContext *m_codec_ctx;
    AVCodec *m_codec;
public:
    explicit T_Box_Media(T_Box_Control *a_control, AVMediaType a_media_type);
    bool isValid();
};

#endif // T_BOX_MEDIA_H
